package com.order.mapper;

import com.order.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {

    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> getByUserId(Long userId);

    @Insert("insert into shopping_cart(user_id, product_id, quantity, amount, name, image)" +
            " values " +
            "(#{userId}, #{productId}, #{quantity}, #{amount}, #{name}, #{image})")
    void insert(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{userId} and product_id = #{productId}")
    ShoppingCart selectByUserIdAndProductId(Long userId, Long productId);

    @Update("update shopping_cart set quantity = #{quantity}, amount = #{amount} where id = #{id}")
    void update(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where id = #{id}")
    ShoppingCart getById(Long id);


    void deleteByIds(List<Long> ids);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);
}
